package com.play.ballen.splash

import android.content.Intent
import com.play.ballen.R
import com.play.ballen.config.KVConst
import com.play.ballen.databinding.ActivitySplashBinding
import com.play.ballen.home.ui.AddInformationActivity
import com.play.ballen.home.ui.MainActivity
import com.play.ballen.me.ui.OneKeyLoginActivity
import com.play.ballen.utils.UserInfoManager
import com.yuven.appframework.util.MMKVUtil
import com.yuven.appframework.util.MMKVUtil.decodeString
import com.yuven.baselib.component.BaseMVVMActivity

class SplashActivity : BaseMVVMActivity<SplashVM, ActivitySplashBinding>() {

    override fun layoutId(): Int {
        return R.layout.activity_splash
    }

    override fun viewModelClass(): Class<SplashVM> {
        return SplashVM::class.java
    }

    override fun initView() {
        viewModel.readUserInfoFromMMKV()
    }

    override fun initObserver() {
        super.initObserver()
        viewModel.actionReadUserComplete.observe(this) {
             if (UserInfoManager.isLogin()) {
                 var photo = MMKVUtil.decodeString(KVConst.PHOTO,false)?:""
                 var name = MMKVUtil.decodeString(KVConst.NICK_NAME,false)?:""
                 if(photo.isEmpty()||name.isEmpty()){
                     AddInformationActivity.start(mContext)
                 }else{
                     MainActivity.start(this)
                 }
            } else {
                val intent = Intent(this@SplashActivity, OneKeyLoginActivity::class.java)
                startActivity(intent)
            }
            finish()
        }
    }

    override fun initData() {
    }

    override fun initIntent(intent: Intent?) {

    }
}